package com.twu.biblioteca.view.command;

import com.google.inject.Inject;

import com.twu.biblioteca.controller.BookController;
import com.twu.biblioteca.entity.Book;
import com.twu.biblioteca.view.console.ConsoleViewController;

public class BookCheckoutCommand extends Command {
  private final BookController bookController;

  @Inject
  public BookCheckoutCommand(BookController bookController) {
    this.bookController = bookController;
  }

  public void execute(ConsoleViewController viewController) {
    int availableBookSize = viewController.getAvailableBookSize();
    this.consoleWriter.display(String.format("Enter a number to checkout a book [1 to %d]: ",
        availableBookSize));
    int itemToCheckout = this.consoleReader
        .readLineAndConvertInt(availableBookSize, "Enter a number to checkout a book [1 to %d]: ");
    Book bookToCheckout = viewController.getBookToCheckout(itemToCheckout);
    bookController.checkout(bookToCheckout);
  }
}
